import records
import pandas as pd

db_user = 'root'
db_pass = ''
db_host = '127.0.0.1'
db_port = '3306'
table = 'table_name'

if __name__ == '__main__':
    db = records.Database(f"mysql+pymysql://{db_user}:{db_pass}@{db_host}:{db_port}/{table}")
    c= db.query(f'select table_name from information_schema.tables where table_schema="{table}"')
    a = c.as_dict()
    e = pd.DataFrame()
    for i in a:
        print(i['table_name'])
        sql_str = f"SELECT table_name 表名,COLUMN_NAME 字段名,DATA_TYPE 数据类型,column_comment 字段注释 FROM INFORMATION_SCHEMA.Columns WHERE table_name='{i['table_name']}' AND table_schema='hengdian_vr'"
        d = pd.DataFrame(db.query(sql_str).as_dict())
        e = pd.concat([e, d])
        print(d)
        d.to_excel(f'table_list/{i["table_name"]}.xlsx')
        # break
    e.to_excel('table_list/all.xlsx')